package com.maven.front.controller.manageCourseDetailCon;

import com.maven.front.bean.EduCourse;
import com.maven.front.bean.EduWebsiteCourseDetail;
import com.maven.front.bean.Result;
import com.maven.front.dto.EduCourseDto;
import com.maven.front.service.manageCourse.EduCourseService;
import com.maven.front.service.manageCourseDetail.CourseDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @descriptions: 推荐课程操作类
 * @author:
 * @date: 2020/8/14 11:51
 * @version: 1.0
 */

@Slf4j
@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("admin/courseDetail")
public class EduWebsiteDetailController {

    @Autowired
    private CourseDetailService courseDetailService;
    @Autowired
    private EduCourseService eduCourseService;

//    对推荐课程的全部查询以及条件查询
    @GetMapping("AllDetail")
    public Result AllDetail(String courseName){
        return courseDetailService.selectAll(courseName);
    }


    @GetMapping("showAllDetail")
    public Result showAllDetail(){
        List<EduCourseDto> list = eduCourseService.listAll(null);
        List<EduWebsiteCourseDetail> listDetail = courseDetailService.listAllDetail();
        Map map = new HashMap();
        map.put("listDto", list);
        map.put("listDetail", listDetail);
        return new Result(200, "查询成功！", map);
    }


    //    根据推荐课程表的ID删除数据
    @PostMapping("delDetail")
    public Result delDetail(int courseId){
        return courseDetailService.delDetail(courseId);
    }


//    获取修改数据
    @GetMapping("getWebsitCourse")
    public Result getWebsitCourse(Integer courseId){
        return courseDetailService.getWebsitCourse(courseId);
    }
//    根据ID，修改当前数据的排序数值
    @PostMapping("editDetail")
    public Result editDetail(Integer courseId, Integer orderNum){
        return courseDetailService.editDetail(courseId, orderNum);
    }

//    新增首页推荐课程时，获取所有可添加课程
    @GetMapping("getEduCourse")
    public Result getEduCourse(EduCourse eduCourse){
        if(ObjectUtils.isEmpty(eduCourse)){
            log.info("进入空");
        } else {
            log.info("不为空："+eduCourse.getCourseName()+":"+eduCourse.getSubjectLink());
        }
        return courseDetailService.getEduCourse(eduCourse);
    }

//    新增首页推荐课程
    @PostMapping("AddDetail")
    public Result AddDetail(String courseId){
        return courseDetailService.AddDetail(courseId);
    }


}
